import http from "./axios";

// 登录的接口
function login(params) {
  let data = http.post("/login", params);
  return data;
}

// 用户列表接口
function userList(params) {
  let data = http.get("/users", { params });
  return data;
}

// 左侧菜单权限
function menus() {
  let data = http.get("/menus");
  return data;
}

// 添加用户列表
function add(obj) {
  let data = http.post("users", obj);
  return data;
}

// 修改用户的状态
function togStatus(obj) {
  let data = http.put(`/users/${obj.id}/state/${obj.mg_state}`);
  return data;
}

// 确认修改用户列表数据
function modify(obj) {
  let data = http.put(`/users/${obj.id}`, obj);
  return data;
}

// 删除用户信息
function delUser(obj) {
  let data = http.delete(`/users/${obj.id}`);
  return data;
}

// 获取分配角色列表
function fJsList(obj) {
  let data = http.put(`/users/${obj.userid}/role`, { rid: obj.role_id });
  return data;
}

// 获取角色列表
function getRolesList() {
  let data = http.get("/roles");
  return data;
}

// 确认添加角色
function qRolesAdd(obj) {
  let data = http.post("/roles", obj);
  return data;
}

// 删除角色
function DelRoles(obj) {
  let data = http.delete(`roles/${obj.id}`);
  return data;
}

// 确认修改角色
function qRolesEdit(obj) {
  let data = http.put(`roles/${obj.id}`, obj);
  return data;
}

// 获取所有权限列表类型是tree
function getPermissionsTree() {
  let data = http.get(`rights/tree`);
  return data;
}
// 获取所有权限列表类型是list
function getPermissionsList() {
  let data = http.get(`rights/list`);
  return data;
}

// 删除角色指定权限
function DelRolesPermissions(obj) {
  let data = http.delete(`roles/${obj.myid}/rights/${obj.tag.id}`);
  return data;
}

// 更新角色权限
function UpdatePermissions(obj){
   let data = http.post(`roles/${obj.id}/rights`,{rids:obj.str});
   return data
}



// 商品分类页
// 获取商品分类列表
function getGoodsList(obj){
  let data = http.get("categories",{params:obj});
  return data
}

// 添加商品分类
function AddGoodsType(obj){
  let data = http.post("categories",obj);
  return data
}

// 删除商品分类
function delGoodsType(obj){
  let data = http.delete(`categories/${obj.cat_id}`,obj.cat_name);
  return data
}

// 确认修改商品分类
function TypeEdit(obj){
  let data = http.put(`categories/${obj.id}`,{cat_name:obj.cat_name});
  return data
}



// 分类参数页
// 获取参数列表
function getParamsList(obj){
  let data = http.get(`categories/${obj.id}/attributes?sel=${obj.sel}`);
  return data
}

// 添加tag
function addParams1(obj){
  let data = http.put(`categories/${obj.id}/attributes/${obj.attr_id}`, {
    attr_name: obj.attr_name,
    attr_sel: obj.attr_sel,
    attr_vals: obj.attr_vals,
  });
  return data
}

// 添加参数
function addparams2(obj){
  let data = http.post(`categories/${obj.id}/attributes`,{attr_name:obj.attr_name,attr_sel:obj.attr_sel});
  return data
}

// 删除参数
function delParams(obj){
  let data = http.delete(`categories/${obj.id}/attributes/${obj.attrid}`);
  return data
}

// 修改参数
function editParams(obj){
  let data = http.put(`categories/${obj.id}/attributes/${obj.attrid}`,obj);
  return data
}

// 删除tag标签
function tagDel(obj){
  let data = http.put(`categories/${obj.id}/attributes/${obj.attrid}`,obj);
  return data
}



// 商品列表页
// 获取商品列表数据
function getGoods(obj){
  let data = http.get('goods',{params:obj});
  return data
}

// 添加商品
function addgood(obj){
  let data = http.post('goods',obj);
  return data
}

// 数据统计
function reports(){
  let data = http.get("reports/type/1");
  return data
}


export {
  login,
  userList,
  menus,
  add,
  togStatus,
  modify,
  delUser,
  getRolesList,
  qRolesAdd,
  DelRoles,
  qRolesEdit,
  getPermissionsTree,
  getPermissionsList,
  DelRolesPermissions,
  fJsList,
  UpdatePermissions,
  getGoodsList,
  AddGoodsType,
  delGoodsType,
  TypeEdit,
  getParamsList,
  addParams1,
  addparams2,
  delParams,
  editParams,
  tagDel,
  getGoods,
  addgood,
  reports,
};
